package org.ricks.log;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author chenwei
 * @Description: 实时刷新，写入文件就立刻刷新
 * 定时刷新其一实时性不行，其二压测性能不如实时刷新
 * @date 2023/1/916:58
 */
class LogFile {
    private final FileWriter fileWriter;
    private final BufferedWriter bufferedWriter;

    LogFile(File file) throws IOException {
        this.fileWriter = new FileWriter(file, true);
        this.bufferedWriter = new BufferedWriter(fileWriter);
    }

    void writer(char[] text) throws IOException {
        bufferedWriter.write(text);
    }

    public void flush() throws IOException {
        bufferedWriter.flush();
    }

    public void close() throws IOException {
        bufferedWriter.close();
        fileWriter.close();
    }
}
